#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 17:10
# @Author: 王思淇
# @Email: xxx@gmail.com
# @File：new_tesk_page.py



from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST
from selenium.webdriver.support.select import Select
from time import sleep

input_subject = "用例评审"

class NewTeskPage(BasePage):
    """添加线索页面类"""
    url = "http://{}/crm/index.php?m=task&a=add".format(HOST)
    subject_locator = (By.NAME, 'subject')  # 主题
    message_alert_locator = (By.NAME, 'message_alert')  # 站内信发送
    owner_name_locator = (By.NAME, 'owner_name')  # 负责人
    to_role_id_locator = (By.XPATH, '//*[@id="ta1"]/input')  # 选择负责人
    ui_button_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')  # ok
    about_roles_name_locator = (By.XPATH, '//*[@id="about_roles_name"]')  # 选择任务相关人
    muti_role_id_locator = (By.CSS_SELECTOR, '#ta1 > span:nth-child(3) > input')  # 选择admin
    ui_widget_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]/span')  # 选择ok
    due_date_locator = (By.ID, 'due_date')  # 选择日期
    status_select = (By.NAME, 'status')  # 状态
    priority_select = (By.NAME, 'priority')  # 优先级
    ke_content_locator = (By.XPATH, '/html/body')  # 描述
    baocun_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  # 保存
    # 断言
    alert_success_locator = (By.CLASS_NAME, "alert-success")

    all_role_id_locator = (By.XPATH, '//*[@id="ta1"]/input')  # 选择全部负责人
    all_muti_role_id_locator = (By.CSS_SELECTOR,'#ta1 > input')        #选择全部相关人
    #保存并新建
    and_new_locator = (By.CSS_SELECTOR, 'body > div.container > div.row-fluid > div > form > table > tfoot > tr > '
                                 'td:nth-child(2) > input:nth-child(2)')


    #新建添加成功
    new_succeed = (By.XPATH,"/html/body/div[5]/div[2]/div/div")

    #返回
    return_baocun_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[3]')   #返回

    # 邮件形式发送
    email_alert_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[4]/input[2]')

    #修改文件里的返回
    button_xg_return_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tfoot > tr"
                                                " > td:nth-child(2) > input:nth-child(2)")


    def input_contacts(self,input_subject):
        """输入主题"""
        self.driver.find_element(*self.subject_locator).send_keys(input_subject)

    def click_save_btn(self):
        """取消默认选择站内信"""
        self.driver.find_element(*self.subject_locator).click()

    def click_sava_btns(self):
        """选择站内信"""
        self.driver.find_element(*self.subject_locator).click()
    def click_owner_name(self):
        """点击负责人"""
        self.driver.find_element(*self.owner_name_locator).click()
    def click_to_role_id(self):
        """选择负责人"""
        self.driver.find_element(*self.to_role_id_locator).click()

    def click_ui_button(self):
        """ok"""
        self.driver.find_element(*self.ui_button_locator).click()
    def clike_about_roles_name(self):
        """选择相关人员"""
        self.driver.find_element(*self.about_roles_name_locator).click()
    def clike_about_roles_names(self):
        self.driver.find_element(*self.muti_role_id_locator).click()

    def clike_ui_widget(self):
        self.driver.find_element(*self.ui_widget_locator).click()

    def input_due_date(self,due_date):
        """日期"""
        self.driver.find_element(*self.due_date_locator).send_keys(due_date)

    def source_select_by_visible_text(self,input_status):
        """状态"""
        select = self.driver.find_element(*self.status_select)
        Select(select).select_by_visible_text(input_status)

    def priority_select_by_visible_text(self,priority):
        """优先级"""
        select = self.driver.find_element(*self.priority_select)
        Select(select).select_by_visible_text(priority)

    def input_ke_content(self,ke_content):
        """描述"""
        self.driver.find_element(*self.ke_content_locator).send_keys(ke_content)
    def clike_baocuns(self):
        """保存"""
        self.driver.find_element(*self.baocun_locator).click()

    def alert_success(self):
        success = self.driver.find_element(*self.alert_success_locator).text
        return success

    def click_all_roles_id(self):
        """选择全部负责人"""
        self.driver.find_element(*self.all_role_id_locator).click()

    def clike_all_about_roles(self):
        """选择全部相关人员"""
        self.driver.find_element(*self.all_muti_role_id_locator).click()

    def clike_and_new(self):
        """保存并新建"""
        self.driver.find_element(*self.and_new_locator).click()

    def add_new_succeed(self):
        """添加成功"""
        tj = self.driver.find_element(*self.new_succeed).text
        return tj
    def task_return(self):
        """返回"""
        self.driver.find_element(*self.return_baocun_locator).click()

    def email_alert(self):
        """邮件发送"""
        self.driver.find_element(*self.email_alert_locator).click()

    def button_xg_return(self):
        """修改任务的返回"""
        self.driver.find_element(*self.button_xg_return_locator).click()

    def alert_success_tasck(self):
        """搜索"""
        success = self.driver.find_element(*self.alert_success_locator).text
        return success
    def success_tasck(self):
        success = self.driver.find_element(*self.alert_success_locator).text
        return success






    def new_tesk_func(self,input_subject):
        """必填"""
        self.input_contacts(input_subject) #主题
        sleep(1)
        self.click_owner_name() #点击负责人
        sleep(2)
        self.click_to_role_id() #选择负责人admin
        sleep(2)
        self.click_ui_button()  #ok
        sleep(1)
        self.clike_baocuns()  # 保存




    def new_tesks_func(self):
        """全部填写"""
        self.input_contacts()  # 主题
        self.click_owner_name()  # 点击负责人
        self.click_to_role_id()  # 选择负责人admin
        self.click_ui_button()  #ok
        self.clike_about_roles_name()  #点击相关人员
        self.clike_about_roles_names()  #相关人员admin
        self.click_ui_button() #ok
        self.input_due_date()  #日期
        self.source_select_by_visible_text()   #状态
        self.priority_select_by_visible_text()  #优先级
        self.input_ke_content()   #描述
        self.clike_baocuns()   #保存






















